/////precompiled////////
#include "precompiled.h"
////////////////////////

#include "prs_Converter.h"
using namespace prs;

// TConverter /////////////////////////////////////////////////////////////////

//
TConverter::TConverter()
:RUnit(SntContext,vNodeUnit)
{
}
                  
//
bool TConverter::TextToNodeUnit(
  svl::TText &FromText,
  TNodeUnit &ToNodeUnit
){
  ToNodeUnit.SntConcreteContext.Text.CopyFrom(FromText);
  SntContext.Push(&ToNodeUnit.SntConcreteContext);

  vNodeUnit = &ToNodeUnit;

  if (!RUnit.Execute()) {
    svl::TMessageModal(svl::TString("Errors")
      << "\r\n" << SntContext.GetErrorsInfo()
      //<< "\r\nToNodeUnit:\r\n" << ToNodeUnit.GetInfoAsString()
    );
    return false;
  }
  
  return true;
}

/*****************
//
bool TConverter::FileToNodeUnit(    
  svl::TString &Path,
  svl::TString &FromFileName,
  TNodeUnit &ToNodeUnit
){
  ToNodeUnit.Path = Path;
  ToNodeUnit.FileName = FromFileName;

  svl::TText Text;
  Text.LoadFromFile(Path + FromFileName);
  
  return TextToNodeUnit(Text,ToNodeUnit);
}
*********************/

//
bool TConverter::FileToNodeRoot(
  svl::TString &Path,
  svl::TString &FromFileName,
  TNodeRoot    &ToNodeRoot
){
  TNodeUnit *NodeUnit = new TNodeUnit;
  ToNodeRoot.Units.Array.AddLast(NodeUnit,true);

  NodeUnit->Path = Path;
  NodeUnit->FileName = FromFileName;

  svl::TText Text;
  Text.LoadFromFile(Path + FromFileName);
  
  return TextToNodeUnit(Text,*NodeUnit);
/****
  if (!TextToNodeUnit(Text,*NodeUnit)) {
    svl::TMessageModal(svl::TString("FileToNodeRoot:")
      << "\r\nToNodeRot:\r\n" << ToNodeRoot.GetInfoAsString()
    );
  }
  return true;
*****/  
}
